// view/index/addpublics/addpublics.js
let app = getApp()
let yuming = app.globalData.yuming
let reg = app.globalData.mobile
var chaninese = app.globalData.chaninese
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    showMieChong:false,
    show: false,
    danwei:'',
    buttonClicked: false,
    yuming: yuming,
    heights: "",
    title: '',
    photo: [],
    wuphoto: '',
    id: '',
    leilist: [{
      name: '植物油',
      id: 1
    }, {
      name: '制糖',
      id: 2
    }], //类别
    leindex: 0,
    chulist: ['利利', '张伟'], //处理人
    chuindex: 0,
    sheng: '',

    xdxdlist: [{
      name: 'sd',
      id: 1
    }, {
      name: 'ee',
      id: 2
    }], //洗涤消毒分类
    xdxdfl: '',
    xdxdflid: '',
    xdxdguo: '请选择分类',
    sdxdsl: '1', //洗涤消毒数量
    sdxdmc: '', //洗涤消毒名称
    sdxdcs: '', //洗涤消毒厂商
    xdxdpp: '', //洗涤消毒品牌
    xdxdyxq: '请选择时间', //洗涤消毒有效期

    leiguo: '请选择类别', //废弃油脂类别
    fqyzsl: '', //废弃油脂数量
    chuguo: '请选择处理人',
    sgdwindex: 0,
    sgdwlist: [],
    sgdwid: '',
    sgdwguo: '请选择收购单位', //废弃油脂收购单位
    fqyzdz: '', //废弃油脂地址
    // chuid:'',//食材质检处理人id
    leiid: '', //废弃油脂类别id
    cltimeguo: '请选择时间', //处理时间
    fqyzyt: '', //用途
    bindsgr: '', //收购人
    bindsgrdian: '', //收购人电话

    sczjfl: '', //食材质检分类
    sczjsl: '', //食材质检数量
    sczjmc: '', //食材质检名称
    sczjfllist: [], //食材质检分类
    sczjflindex: 0, //食材质检index
    sczjflguo: '请选择分类', //食材质检分类
    sczjflid: '', //食材质检id
    sczjjcr: '', //食材质检检测人

    mcglrylist: [],
    mcglryindex: 0,
    mcglryid: '',
    mcglryguo: '请选择使用人员',
    bindmcsyyp: '', //使用药品
    bindmcsysl: '', //数量
    mchfs: '', //灭虫害方式
    mcypjx: '', //灭虫药品机械
    shiguo: '请选择时间', //灭虫害时间
    bindmchsymd: '', //使用目的
    bindmcsyqy: '', //使用区域
    bindmcpznd: '', //配置浓度
    bindmcbuytime: '请选择购买时间',

    tjjcpm: '', //添加剂产品名
    tjjcd: '', //添加剂产地
    tjjxkh: '', //添加剂许可号
    tjjgg: '', //添加剂规格
    tjjzycf: '', //添加剂主要成分
    tjjpcdh: '', //添加剂产批次代号
    tjjbzq: '', //添加剂保质期
    tjjsyff: '', //添加剂使用方法
    shengguo: '请选择生产日期', //添加剂生产日期
    bindtjjfwyl: '', //范围用量
    page: 1,
    scnum: 9,

    gysindex: 0,
    gyslist: [],
    gysid: '',
    gysguo: '请选择',
    tongyi:'',
    shbeilist:[],
    shbeilistname:'请选择消毒设备',
    checked:false,
    startTime:'',
    minHour: 10,
    maxHour: 20,
    minDate: new Date().getTime() - 43200000,
    maxDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    currentDateMieChong: new Date().getTime(),
  },
  timestampToTime2(timestamp) {
            if (timestamp === 0 || timestamp == null) {
              return ''
            } else {
              var date = new Date(timestamp)
              var Y = date.getFullYear() + '-'
              var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
              var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
              var H = date.getHours() + ':'
              var M2 = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
            //   var S = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
              return Y + M + D + H + M2 
            }
          },
  onInput(event) {

    

    this.setData({
      currentDate: event.detail,
      xdxdyxq:this.timestampToTime2(event.detail),
      show:false
    });
  },
  onInputMieChong(event) {

    

    this.setData({
      currentDateMieChong: event.detail,
      shiguo:this.timestampToTime2(event.detail),
      showMieChong:false
    });
  },
  showPopup() {
    this.setData({ show: true });
  },
  showPopupMieChong() {
    this.setData({ showMieChong: true });
  },
 
  onClose() {
    this.setData({ show: false });
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  // 提交
  tijiao() {
    if(this.data.tongyi != 'true'){
        wx.showToast({
          title: '请阅读上报说明',
          icon:'error'
        })
        return
    }


    if (this.data.id == 5) {
      this.xdxdyz()
    }
    if (this.data.id == 6) {
      this.fqyzyz()
    }
    if (this.data.id == 7) {
      this.sczjyz()
    }
    if (this.data.id == 14) {
      this.mcgl()
    }
    if (this.data.id == 8) {
      this.tjjgl()
    }
  },
  // 数量
  shuliang(e) {
    console.log(e)
    var lll = e.detail.value
    this.setData({
      sdxdsl: lll
    })
    if (lll.length >= 4) {
      wx.showToast({
        title: '只能输入四位哦~',
        icon: 'none'
      })
    }
  },
  // 减
  jian() {
    var num = this.data.sdxdsl
    if (num == 1) {
      this.setData({
        sdxdsl: 1
      })
    } else {
      num--
      this.setData({
        sdxdsl: num
      })
    }
  },
  // 加
  jia() {
    var num = this.data.sdxdsl
    num++
    this.setData({
      sdxdsl: num
    })
  },
  // 洗涤消毒分类
  bindxdxd(e) {
    this.setData({
      xdxdguo: this.data.xdxdlist[e.detail.value].name,
      xdxdflid: this.data.xdxdlist[e.detail.value].id,
    })
  },
  // 洗涤消毒品牌
  xdxdpp(e) {
    this.setData({
      xdxdpp: e.detail.value
    })
  },
  // 洗涤消毒名称
  sdxdmc(e) {
    this.setData({
      sdxdmc: e.detail.value
    })
  },
  // 洗涤消毒厂商
  sdxdcs(e) {
    this.setData({
      sdxdcs: e.detail.value
    })
  },
  // 洗涤消毒有效期
  bindDateChange: function (e) {
    this.setData({
      xdxdyxq: e.detail.value
    })
  },

  // 获取当前时间 只能选择目前时间
  getThisTime(){
    //小于10的拼接上0字符串
function addZero(s) {
  return s < 10 ? ('0' + s) : s;
}
    var date = new Date();
    //年 getFullYear()：四位数字返回年份
    var year = date.getFullYear();  //getFullYear()代替getYear()
    //月 getMonth()：0 ~ 11
    var month = date.getMonth() + 1;
    //日 getDate()：(1 ~ 31)
    var day = date.getDate();
    //时 getHours()：(0 ~ 23)
    var hour = date.getHours();
    //分 getMinutes()： (0 ~ 59)
    var minute = date.getMinutes();
    //秒 getSeconds()：(0 ~ 59)
    var second = date.getSeconds();

    var time =year + '-' + addZero(month) + '-' + addZero(day);
    this.setData({
      startTime:time
    })
    console.log(this.data.startTime);
  },

  // 洗涤消毒上报
  
  shbeilist(){
    // var that = this
    this.myRequest(yuming +'Shopthat/clean_device_list',{
      shopId: wx.getStorageSync('shopId'),
      page: this.data.page,
      // keywords: this.data.keywords

    },'POST').then(res =>{
      console.log( res.data.data);
      this.setData({
        shbeilist:res.data.data
      })
      // this.shbeilist = 
    })
  },
  // 洗涤消毒验证
  xdxdyz() {
    if (this.data.chuguo == '请选择处理人') {
      wx.showToast({
        title: '请选择消毒人',
        icon: 'none'
      })
    } else 
    if (this.data.shbeilistname == '请选择消毒设备') {
      wx.showToast({
        title: '请输入消毒设备',
        icon: 'none'
      })
    } else if (this.data.sdxdcs == '') {
      wx.showToast({
        title: '请输入消毒区域',
        icon: 'none'
      })
    }
    //  else if (this.data.xdxdpp == '') {
    //   wx.showToast({
    //     title: '请输入品牌',
    //     icon: 'none'
    //   })
    // }
     else if (this.data.xdxdyxq == '请选择时间') {
      wx.showToast({
        title: '请选择消毒时间',
        icon: 'none'
      })
    } else if (this.data.photo == '') {
      wx.showToast({
        title: '请上传图片',
        icon: 'none'
      })
    } else {
      this.xdxdjk()
    }
  },
   // 验证是否有员工
   yanzheng(){
    if(this.data.chulist.length === 0){
      wx.showToast({
        title: '请先添加员工',
        icon:"error"
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/page_one/addyuan/addyuan',
        })
      },1000)
    }
  },
  yanzhengshebei(){
    if(this.data.shbeilist.length === 0){
      wx.showToast({
        title: '请先添加设备',
        icon:"error"
      })
        setTimeout(()=>{
        wx.navigateTo({
          url: '/page_two/xdxd/xdxd',
        })
      },1000)
    }
  },
  yanzhengs(){
    if(this.data.gyslist.length === 0){
      wx.showToast({
        title: '请先添加收购商',
        icon:"error"
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/page_one/addgys/addgys?addid=' + 6 + '&addtitle=报备收购商',
        })
      },1000)
    }
  },
  yanzhengsc(){
    if(this.data.mcglrylist.length === 0){
      wx.showToast({
        title: '请先添加员工',
        icon:"error"
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/page_one/addyuan/addyuan',
        })
      },1000)
    }
  },
  yanzhengssc(){
    if(this.data.gyslist.length === 0){
      wx.showToast({
        title: '请先添加质检商',
        icon:"error"
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/page_one/addgys/addgys?addid=' + 7 + '&addtitle=报备质检商',
        })
      },1000)
    }
  },
  yanzhneggys(){
    if(this.data.gyslist.length === 0){
      wx.showToast({
        title: '请先添加供应商',
        icon:"error"
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/page_one/addgys/addgys?addid=' + 8  + '&addtitle=报备供应商',
        })
      },1000)
    }
  },
  yanzhengGYSMC(){
    if(this.data.gyslist.length === 0){
      
      wx.showToast({
        title: '请先添加供应商',
        icon:"error"
      })
      setTimeout(()=>{
        wx.navigateTo({
          url: '/page_one/addgys/addgys?addid=' + 14 + '&addtitle=报备供应商',
        })
      },1000)
    }
  },
  agreement(){
  

    if(this.data.id == 5){
      wx.navigateTo({
        url: '/page_two/shuoming/shuoming?cid=284'
      })
    }else{
      wx.navigateTo({
        url: '/page_two/shuoming/shuoming?cid=' + this.data.cid,
      })
    }
  },
  // 洗涤消毒接口
  xdxdjk() {
    var that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'shop/shopAddCleanlog', {
      shopId: wx.getStorageSync('shopId'),
      // cleanClass: that.data.xdxdguo,
      cleanName: that.data.shbeilistname,
      cleanNumer: that.data.sdxdsl,
      cleanBrand: that.data.xdxdpp,
      manufacturer: that.data.sdxdcs,
      validityTime: that.data.xdxdyxq,
      cleanImage: that.data.wuphoto,
      staffName:that.data.chuguo
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.navigateBack({
            delta: 0
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },

  // 废弃油脂类别
  bindlei(e) {
    var index = e.detail.value
    this.setData({
      leiguo: this.data.leilist[index].name,
      leiid: this.data.leilist[index].id
    })
  },
  // 废弃油脂处理人
  bindchu(e) {
    let index = e.detail.value
    this.setData({
      chuguo: this.data.chulist[index].Name,
      chuid: this.data.chulist[index].id
    })
  },
  bindshbei(e){
    let index = e.detail.value
    console.log(e);
    this.setData({
      shbeilistname: this.data.shbeilist[index].name,
      shbeilistnameid: this.data.shbeilist[index].id
    })
  },
  // 收购人电话
  bindsgrdian(e) {
    this.setData({
      bindsgrdian: e.detail.value
    })
  },
  // 收购人
  bindsgr(e) {
    this.setData({
      bindsgr: e.detail.value
    })
  },
  // 用途
  fqyzyt(e) {
    this.setData({
      fqyzyt: e.detail.value
    })
  },
  // 废弃油脂处理时间
  bindcltime(e) {
    if (new Date(e.detail.value).getTime() > Date.parse(new Date())) {
      wx.showToast({
          title: '收购不可大于当前时间',
          icon: 'none'
      })
      this.setData({
        cltimeguo: '请选择时间',
      })
      return
  }

    this.setData({
      cltimeguo: e.detail.value
    })
  },
  // 废弃油脂地址
  fqyzdz(e) {
    this.setData({
      fqyzdz: e.detail.value
    })
  },
  // 废弃油脂获取处理人
  cylist() {
    var that = this
    this.myRequest(yuming + 'shop/shopSelectStaff', {
      page: -1,
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      that.setData({
        chulist: res.data.result,
      })
    })
  },
  // 废弃油脂验证
  fqyzyz() {
    if (this.data.leiguo == '请选择类别') {
      wx.showToast({
        title: '请选择类别',
        icon: 'none'
      })
    } else if (this.data.chuguo == '请选择处理人') {
      wx.showToast({
        title: '请选择处理人',
        icon: 'none'
      })
    } 
    // else if (this.data.bindsgr == '') {
    //   wx.showToast({
    //     title: '请输入收购人',
    //     icon: 'none'
    //   })
    // } 
    // else if (this.data.bindsgrdian == '') {
    //   wx.showToast({
    //     title: '请输入收购人电话',
    //     icon: 'none'
    //   })
    // } 
    // else if (reg.test(this.data.bindsgrdian) == false) {
    //   wx.showToast({
    //     title: '请输入正确的手机号',
    //     icon: "none"
    //   })
    // } 
    else if (this.data.gysguo == '请选择收购单位') {
      wx.showToast({
        title: '请选择收购单位',
        icon: 'none'
      })
    } 
    // else if (this.data.fqyzdz == '') {
    //   wx.showToast({
    //     title: '请输入收购地址',
    //     icon: 'none'
    //   })
    // }
     else if (this.data.cltimeguo == '请选择处理时间') {
      wx.showToast({
        title: '请选择收购时间',
        icon: 'none'
      })
    }
    //  else if (this.data.fqyzyt == '') {
    //   wx.showToast({
    //     title: '请输入用途',
    //     icon: 'none'
    //   })
    // }
     else if (this.data.photo.length == 0) {
      wx.showToast({
        title: '请上传图片',
        icon: 'none'
      })
    } else {
      this.fqyzjk()
    }
  },
  checkboxChange(e){
    console.log(e);
    let tongyi = e.detail.value
    this.setData({
        tongyi:tongyi
    })
  },
  // 废弃油脂接口
  fqyzjk() {
    let that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'shop/shopAddGreaselog', {
      shopId: wx.getStorageSync('shopId'),
      greaseClass: that.data.leiguo,
      greaseNumber: that.data.sdxdsl ,
      greaseUnit:that.data.danwei,
      shopGaff: that.data.chuguo,
      proTime: that.data.cltimeguo,
      acquisitionName: that.data.bindsgr,
      acquisitionPhone: that.data.bindsgrdian,
      acquisitionUnit: that.data.gysguo,
      purpose: that.data.fqyzyt,
      acquisitionDress: that.data.fqyzdz,
      acquisitionImage: that.data.wuphoto
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.navigateBack({
            delta: 0
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },

  // 食材质检分类
  bindsczjfl(e) {
    var index = e.detail.value
    this.setData({
      sczjflguo: this.data.sczjfllist[index].name,
      sczjflid: this.data.sczjfllist[index].id
    })
  },
  // 食材质检提交人
  bindsczjtjr(e) {
    var index = e.detail.value
    this.setData({
      sczjtjrguo: this.data.sczjtjrlist[index].cartName,
      sczjtjrid: this.data.sczjtjrlist[index].id
    })
  },

  danwei(e){
    // console.log(e);
    this.setData({
      danwei: e.detail.value
    })
  },
  // 食材质检分类地址
  // sczjfl(e) {
  //   this.setData({
  //     sczjfl: e.detail.value
  //   })
  // },
  // 食材质检数量
  // sczjsl(e) {
  //   this.setData({
  //     sczjsl: e.detail.value
  //   })
  // },
  // 食材质检名称
  sczjmc(e) {
    this.setData({
      sczjmc: e.detail.value
    })
  },
  bindsczjgys(e) {
    this.setData({
      sczjgysguo: this.data.sczjgyslist[e.detail.value].Name,
      sczjgysid: this.data.sczjgyslist[e.detail.value].id
    })
  },
  // 食材质检检测人
  sczjjcr(e) {
    this.setData({
      sczjjcr: e.detail.value
    })
  },
  // 食材质检验证
  sczjyz() {
    if (this.data.sczjmc == '') {
      wx.showToast({
        title: '请输入名称',
        icon: 'none'
      })
    } else if (this.data.sczjflguo == '请选择分类') {
      wx.showToast({
        title: '请选择分类',
        icon: 'none'
      })
    } else if (this.data.chuguo == '请选择提交人') {
      wx.showToast({
        title: '请选择提交人',
        icon: 'none'
      })
    } 
    // else if (this.data.sczjjcr == '') {
    //   wx.showToast({
    //     title: '请输入检测人',
    //     icon: 'none'
    //   })
    // } 
    else if (this.data.gysguo == '请选择供应商') {
      wx.showToast({
        title: '请选择供应商',
        icon: 'none'
      })
    } else if (this.data.photo == '') {
      wx.showToast({
        title: '请上传图片',
        icon: 'none'
      })
    } else {
      this.sczjjk()
    }
  },
  // 食材质检接口
  sczjjk() {
    let that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'Shop/shopAddFoodquality', {
      shopId: wx.getStorageSync('shopId'),
      fqName: that.data.sczjmc,
      className: that.data.sczjflguo,
      submitter: that.data.chuid,
      // inspector: that.data.sczjjcr,
      fqNum: that.data.sdxdsl,
      
      supplier: that.data.gysid,
      fqImages: that.data.wuphoto
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.navigateBack({
            delta: 0
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },







  // 灭虫
  // 使用药品
  bindmcsyyp(e) {
    this.setData({
      bindmcsyyp: e.detail.value
    })
  },
  // 数量
  bindmcsysl(e) {
    this.setData({
      bindmcsysl: e.detail.value
    })
  },
  // 使用目的
  // bindmchsymd(e) {
  //   this.setData({
  //     bindmchsymd: e.detail.value
  //   })
  // },
  // 使用区域
  bindmcsyqy(e) {
    this.setData({
      bindmcsyqy: e.detail.value
    })
  },
  // 配置浓度
  bindmcpznd(e) {
    this.setData({
      bindmcpznd: e.detail.value
    })
  },
  bindmcglry(e) {
    this.setData({
      mcglryguo: this.data.mcglrylist[e.detail.value].Name,
      mcglryid: this.data.mcglrylist[e.detail.value].id
    })
  },
  // 灭虫人员列表
  mcrylb() {
    var that = this
    this.myRequest(yuming + 'shop/shopSelectStaff', {
      page: -1,
      shopId: wx.getStorageSync('shopId')
    }, "POST").then(res => {
      that.setData({
        mcglrylist: res.data.result,
      })
    })
  },
  // 灭虫害方式
  mchfs(e) {
    this.setData({
      mchfs: e.detail.value
    })
  },
  // 灭虫药品机械
  mcypjx(e) {
    this.setData({
      mcypjx: e.detail.value
    })
  },
  // 灭虫使用时间
  bindtime(e) {
    this.setData({
      shiguo: e.detail.value
    })
  },
  // 灭虫购买时间
  bindbuytime(e) {
    this.setData({
      bindmcbuytime: e.detail.value
    })
  },
  // 灭虫验证
  mcgl() {
    if (this.data.mcglryguo == '请选择使用人员') {
      wx.showToast({
        title: '请选择使用人员',
        icon: 'none'
      })
      // }
      //  else if (this.data.bindmchsymd == '') {
      //   wx.showToast({
      //     title: '请输入使用目的',
      //     icon: 'none'
      //   })
    } else if (this.data.bindmcsyyp == '') {
      wx.showToast({
        title: '请输入使用药品',
        icon: 'none'
      })
    } 
    // else if (this.data.bindmcsysl == '') {
    //   wx.showToast({
    //     title: '请输入数量',
    //     icon: 'none'
    //   })
    // }
     else 
    if (this.data.bindmcsyqy == '') {
      wx.showToast({
        title: '请输入使用区域',
        icon: 'none'
      })
    } else if (this.data.bindmcpznd == '') {
      wx.showToast({
        title: '请输入配置浓度',
        icon: 'none'
      })
    }
    // else if(this.data.mchfs == ''){
    //   wx.showToast({
    //     title: '请输入灭虫害方式',
    //     icon:'none'
    //   })
    // } else if(this.data.mcypjx == ''){
    //   wx.showToast({
    //     title: '请输入药品机械',
    //     icon:'none'
    //   })
    // } 
    else if (this.data.shiguo == '请选择使用时间') {
      wx.showToast({
        title: '请选择使用时间',
        icon: 'none'
      })
    } 
    // else if (this.data.bindmcbuytime == '请选择购买时间') {
    //   wx.showToast({
    //     title: '请选择购买时间',
    //     icon: 'none'
    //   })
    // } 
    else if (this.data.gysguo == '请选择供应商') {
      wx.showToast({
        title: '请选择供应商',
        icon: 'none'
      })
    } else if (this.data.photo == '') {
      wx.showToast({
        title: '请上传图片',
        icon: 'none'
      })
    } else {
      this.mcgljk()
    }
  },
  //  灭虫接口
  mcgljk() {
    let that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'shop/shopAddPestlog', {
      shopId: wx.getStorageSync('shopId'),
      shopStaff: that.data.mcglryguo,
      pestName: that.data.bindmcsyyp,
      pestNum: that.data.bindmcsysl,
      // pestObjective: that.data.bindmchsymd,
      pestRegion: that.data.bindmcsyqy,
      pestCction: that.data.bindmcpznd,
      // pestMode:that.data.mchfs,
      // pestDrugs:that.data.mcypjx,
      pestTime: that.data.shiguo,
      buyTime: that.data.bindmcbuytime,
      supplier: that.data.gysid,
      pestImage: that.data.wuphoto,
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.navigateBack({
            delta: 0
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },

  bindtjjfwyl(e) {
    this.setData({
      bindtjjfwyl: e.detail.value
    })
  },
  // 添加剂产品名
  tjjcpm(e) {
    this.setData({
      tjjcpm: e.detail.value
    })
  },
  // 添加剂产地
  tjjcd(e) {
    if ((chaninese.test(e.detail.value))) {
      wx.showToast({
        title: '只允许输入中文',
        icon: 'none'
      })
      this.setData({
        tjjcd: ''
      })
    } else {
      this.setData({
        tjjcd: e.detail.value
      })
    }
  },
  // 添加剂供应商
  bindtjjgys(e) {
    this.setData({
      tjjgysguo: this.data.tjjgyslist[e.detail.value].Name,
      tjjgysid: this.data.tjjgyslist[e.detail.value].id
    })
  },
  // 添加剂厂名
  // tjjcm(e) {
  //   if ((chaninese.test(e.detail.value))) {
  //     wx.showToast({
  //       title: '只允许输入中文',
  //       icon: 'none'
  //     })
  //     this.setData({
  //       tjjcm: ''
  //     })
  //   } else {
  //     this.setData({
  //       tjjcm: e.detail.value
  //     })
  //   }
  // },
  // 添加剂许可号
  tjjxkh(e) {
    this.setData({
      tjjxkh: e.detail.value
    })
  },
  // 添加剂规格
  tjjgg(e) {
    this.setData({
      tjjgg: e.detail.value
    })
  },
  // 添加剂主要成分
  tjjzycf(e) {
    if ((chaninese.test(e.detail.value))) {
      wx.showToast({
        title: '只允许输入中文',
        icon: 'none'
      })
      this.setData({
        tjjzycf: ''
      })
    } else {
      this.setData({
        tjjzycf: e.detail.value
      })
    }
  },
  // 添加剂产批次代号
  tjjpcdh(e) {
    this.setData({
      tjjpcdh: e.detail.value
    })
  },
  // 添加剂保质期
  tjjbzq(e) {
    this.setData({
      tjjbzq: e.detail.value
    })
  },
  // 添加剂使用方法
  tjjsyff(e) {
    this.setData({
      tjjsyff: e.detail.value
    })
  },
  //  添加剂验证
  tjjgl() {
    if (this.data.tjjcpm == '') {
      wx.showToast({
        title: '请输入添加剂名称',
        icon: 'none'
      })
    } else if (this.data.tjjcd == '') {
      wx.showToast({
        title: '请输入作用范围',
        icon: 'none'
      })
    } else if (this.data.gysguo == '请选择') {
      wx.showToast({
        title: '请选择供应商',
        icon: 'none'
      })
    } 
    // else if (this.data.tjjxkh == '') {
    //   wx.showToast({
    //     title: '请输入许可号',
    //     icon: 'none'
    //   })
    // } 
    else if (this.data.tjjgg == '') {
      wx.showToast({
        title: '请输入贮存条件',
        icon: 'none'
      })
    } else if (this.data.tjjzycf == '') {
      wx.showToast({
        title: '请输入用途描述',
        icon: 'none'
      })
    } else if (this.data.tjjpcdh == '') {
      wx.showToast({
        title: '请输入批次代号',
        icon: 'none'
      })
    } 
    // else if (this.data.tjjbzq == '') {
    //   wx.showToast({
    //     title: '请输入保质期',
    //     icon: 'none'
    //   })
    // } 
    // else if (this.data.tjjsyff == '') {
    //   wx.showToast({
    //     title: '请输入使用方法',
    //     icon: 'none'
    //   })
    // } 
    else if (this.data.bindtjjfwyl == '') {
      wx.showToast({
        title: '请输入用量限制',
        icon: 'none'
      })
    } else if (this.data.shengguo == '请选择生产日期') {
      wx.showToast({
        title: '请选择生产日期',
        icon: 'none'
      })
    } else if (this.data.photo == '') {
      wx.showToast({
        title: '请上传图片',
        icon: 'none'
      })
    } else {
      this.tjjgljk()
    }
  },
  // 添加剂接口
  tjjgljk() {
    var that = this
    that.setData({
      buttonClicked: true
    })
    this.myRequest(yuming + 'shop/shopAdditiveLog', {
      shopId: wx.getStorageSync('shopId'),
      tiveName: that.data.tjjcpm,
      tiveOrigin: that.data.tjjcd,
      tiveFactory: that.data.gysguo,
      tiveLicense: that.data.tjjxkh,
      tiveSpecifications: that.data.tjjgg,
      tiveComponents: that.data.tjjzycf,
      tiveBatchcode: that.data.tjjpcdh,
      tivePeriod: that.data.tjjbzq,
      tiveUsage: that.data.tjjsyff,
      tiveCreatTime: that.data.shengguo,
      rangeOrdosage: that.data.bindtjjfwyl,
      tiveImage: that.data.wuphoto
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        setTimeout(function () {
          wx.navigateBack({
            delta: 0
          })
        }, 1000)
      } else {
        that.setData({
          buttonClicked: false
        })
      }
    })
  },
  // 差掉
  chadiao(e) {
    var index = e.currentTarget.dataset.index
    var photo = this.data.photo;
    var wuphoto = this.data.wuphoto;
    var dd = wuphoto.split(",")
    photo.splice(index, 1)
    dd.splice(index, 1)
    var rr = dd.join(",")
    this.setData({
      photo: photo,
      wuphoto: rr
    })
  },
  // 上传
  chuan(e) {
    var that = this
    var pics = [];
    var wuphoto = this.data.wuphoto;
    this.myChooseImage(9).then(res => {
      const tempFilePaths = res.tempFilePaths
      for (var i = 0; i < tempFilePaths.length; i++) {
        pics.push(tempFilePaths[i])
      }
      if ((pics.length) + (that.data.photo.length) > 9) {
        wx.showToast({
          title: '最多可上传' + 9 + "张",
          icon: 'none'
        })
      } else {
        for (var i = 0; i < tempFilePaths.length; i++) {
          (function (i) { // 注意这里是形参
            setTimeout(function () {
              that.duoupimg(tempFilePaths[i]).then(res => {
                wx.showLoading({
                  title: '上传图片中...',
                });
                var data = JSON.parse(res.data)
                var urls = data.httpUrl + data.imgUrl
                wuphoto = wuphoto.concat(data.imgUrl + ",")
                that.setData({
                  photo: that.data.photo.concat(urls),
                  wuphoto: wuphoto
                });
                if (i == tempFilePaths.length - 1) {
                  wx.hideLoading();
                }
              })
            }, 800 * i); // 还是每秒执行一次，不是累加的
          })(i) // 注意这里是实参，这里把要用的参数传进去
        }
      }
    })
  },
  // 添加剂生产日期
  bindsheng(e) {
    if (new Date(e.detail.value).getTime() > Date.parse(new Date())) {
      wx.showToast({
        title: '生产日期不可大于当前时间',
        icon: 'none'
      })
      this.setData({
        shengguo: '请选择生产日期',
  
      })
    }else{
      this.setData({
        shengguo: e.detail.value
      })
    } 


    // this.setData({
    //   shengguo: e.detail.value
    // })
  },
  // 栏目分类
  lanmufl() {
    let that = this
    let type_mold = '';
    if (that.data.id == 5) {
      type_mold = 50;
    }
    if (that.data.id == 6) {
      type_mold = 51;
    }
    if (that.data.id == 7) {
      type_mold = 52;
    }
    this.myRequest(yuming + 'Besall/public_class_options', {
      type_mold:type_mold
    }, "POST").then(res => {
      if (that.data.id == 5) {
        that.setData({
          xdxdlist: res.data.data
        })
      }
      if (that.data.id == 6) {
        that.setData({
          leilist: res.data.data
        })
      }
      if (that.data.id == 7) {
        that.setData({
          sczjfllist: res.data.data
        })
      }
    })
  },
  // 供应商
  bindgys(e) {
    this.setData({
      gysguo: this.data.gyslist[e.detail.value].supplierName,
      gysid: this.data.gyslist[e.detail.value].id
    })
  },
  getgysList() {
    let that = this
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'shop/ShopSelectSupplier', {
      addid: that.data.id,
      shopId: wx.getStorageSync('shopId'),
      page: '-1'
    }, "POST").then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        that.setData({
          gyslist: res.data.data
        })
        // if (this.data.gyslist.length == 0) {
        //   wx.showToast({
        //     title: '请先报备供应商！',
        //     icon: 'none'
        //   })
        // }
      }
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      title: options.title,
      id: options.id,
      cid: options.cid
    })
    this.cylist();
    this.getThisTime()
    if (this.data.id != 5) {
      this.getgysList();

    }
    if (this.data.id == 6) {
      this.setData({
        gysguo: '请选择收购单位'
      })
      this.cylist();
    }
    if (this.data.id == 7) {
      this.setData({
        chuguo: '请选择提交人'
      })
    }
    if (this.data.id == 8 || this.data.id == 9) {
      this.mcrylb()
    }
    if (this.data.id == 6 || this.data.id == 7 || this.data.id == 8) {
      this.lanmufl()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (this.data.id != 5) {
      this.getgysList();
    }
    if (this.data.id == 6) {
      this.setData({
        gysguo: '请选择收购单位'
      })
      this.cylist();
    }
    if (this.data.id == 7) {
      // this.setData({
      //   mcglryguo: '请选择提交人'
      // })
      this.cylist();

    }
    if(this.data.id == 5){
      this.shbeilist()
    }
    if (this.data.id == 8 || this.data.id == 9 || this.data.id == 14) {
      this.mcrylb()
    }
    if (this.data.id == 6 || this.data.id == 7 || this.data.id == 8) {
      this.lanmufl()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})